<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1">
    <title>添加商品</title>
    <link rel="shortcut icon" th:href="@{/pages/logo-1.ico}" href="../static/pages/logo-1.ico"/>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" href="../static/layui/css/layui.css">
    <link rel="stylesheet" th:href="@{/layui/css/admin.css}" href="../static/layui/css/admin.css">
    <link rel="stylesheet" th:href="@{/layui/css/log.css}" href="../static/layui/css/log.css">
</head>
<body>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class=" layadmin-user-login-header">
            <h2>添加商品</h2>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="id" id="id" lay-verify="required" placeholder="采购商ID" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="name" id="name" lay-verify="required" placeholder="商品名称" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="unit" id="unit" lay-verify="required" placeholder="单位" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="space" id="space" lay-verify="required" placeholder="产地" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="supplierId" id="supplierId" lay-verify="required" placeholder="供应商编号" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="price" id="price" lay-verify="required" placeholder="单价" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="approveId" id="approveId" lay-verify="required" placeholder="批准文号" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="batchId" id="batchId" lay-verify="required" placeholder="生产编号" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-edit"></label>
                <input type="text" name="count" id="count" lay-verify="required" placeholder="数量" class="layui-input">
            </div>
<!--            <div class="layui-inline">-->
<!--&lt;!&ndash;                <label class="layui-form-label">搜索选择框</label>&ndash;&gt;-->
<!--                <div class="layui-input-inline">-->
<!--                    <select name="modules" lay-verify="required" lay-search="">-->
<!--                        <option value="">供应商编号</option>-->
<!--                        <option value="1">layer</option>-->
<!--                        <option value="2">form</option>-->
<!--                    </select>-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit" onclick="submit();" id="addpurlog">确认</button>
            </div>
            <div class="layui-form-item">
                <a href="javascript:history.go(-1);" lay-filter="LAY-user-login-submit" class="layui-btn layui-btn-fluid"  id="out">取消</a>
            </div>
        </div>
    </div>
</div>

<script src="../static/layui/layui.js" th:src="@{/layui/layui.js}" type="text/javascript"></script>
<script src="../static/js/vue.min.js" th:src="@{/js/vue.min.js}" type="text/javascript"></script>
<script src="../static/js/jquery-3.6.3.min.js" th:src="@{/js/jquery-3.6.3.min.js}" type="text/javascript"></script>
<script th:inline="javascript">
    //Javascript代码区域
    //Javascript代码区域
    // window.onload=function() {
    //     let user = [[${user}]];
    //     if (user == null || user == 0) {
    //         window.location.href = "/";
    //     }
    // }

    function submit(){
            let id = $('#id').val()
            let name = $('#name').val()
            let unit = $('#unit').val()
            let space = $('#space').val()
            let supplierId = $('#supplierId').val()
            let price = $('#price').val()
            let approveId = $('#approveId').val()
            let batchId = $('#batchId').val()
            let count = $('#count').val()
            $.ajax({
                url:"/pur/addpur",
                data:{
                    id:id,
                    name:name,
                    unit:unit,
                    space:space,
                    supplierId:supplierId,
                    price:price,
                    approveId:approveId,
                    batchId:batchId,
                    count:count
                },
                type:"post",
                dataType :"json",
                // cache : false,
                // async : false,//设置同步（ajax请求此处需求为跳转而不是局部页面刷新）
                success:function (puradd){
                    if (puradd==100) {
                        window.location.href = "/login/index";
                    }else if (puradd==200) {
                        layer.open({
                            title: ''
                            , content: '系统错误,请联系管理员!'
                        });
                    }else {
                        // window.location.href = "/";
                        layer.open({
                            title: ''
                            ,content: '商品名重复，请重新输入!'
                        });
                    }
                }
            })
        }
</script>
</body>
</html>
